import pageination from '../../components/pageination/pageination.vue'
export default {
	data() {
		return {
			//数据
			total: 0, //总条数
			page: 1, //当前页
			size: 10, //每页显示条数
			search: '', //搜索信息
			fatherIndex: 0, //一级菜单index
			curriculumList: [] //课程列表
		}
	},
	components: {
		pageination
	},
	created() { //调用方法
		//初始化课程分页信息
		this.searchTodo();
	},
	mounted() {

	},
	updated:function(){
		if(this.getParamValue("fatherIndex")){
			this.fatherIndex=this.getParamValue("fatherIndex");
		}
	},
	methods: { //写函数方法
		//页码切换执行方法
		pageFn: function(val, pid) {
			this.page = parseInt(val);
			//此处调列表数据接口
			this.searchTodo(); //查询课程
		},
		/**返回子组件用户选择的一页显示条数**/
		obtainChild: function(data) {
			this.row = data;
		},
		//跳转到修改页面
		gotoUpdate: function(uuid) {
			if(uuid != null && uuid != "") {
				this.set("newResourcesid", uuid);
				this.$router.push({
					path: "/newResources?fatherIndex="+this.fatherIndex,
				})
			}else{
				this.remove("newResourcesid", "");
				this.$router.push({
					path: "/newResources?fatherIndex="+this.fatherIndex,
				})
			}
		},
		//搜索数据列表
		searchTodo: function() {
			let that = this;
			that.$post(
					that.urls.getCurriculumPageInfo, {
						"pageNum": that.page,
						"pageSize": that.size,
						"search": that.search
					}
				)
				.then(function(res) {
					if(res.success) {
						that.curriculumList = res.pageInfo.list;
						that.total = res.pageInfo.total;
						that.page = res.pageInfo.pageNum;
					}
				})
		},
		//删除
		deleteData: function(id, useStatus) {
      let that = this;
		  if(id != null && useStatus == 0) {
        layer.confirm('确定是否删除该课程？', {icon: 3, title:'提示'}, function(index){
          if(id != null) {
            //初始化课程分页信息
            that.$post(
              that.urls.deleteCurriculum, {
                "id": id
              }
            )
            .then(function(res) {
              let msg = "";
              if(res.success) {
                msg = '删除课程成功！';
                //重新渲染数据
                that.searchTodo();
              } else {
                msg = '删除课程失败！';
              }
              layer.msg(msg, {
                time: 3000, //3s后自动关闭
              });
            })
          }
        });
			} else if(id != null && useStatus == 1) {
        layer.confirm('若删除则会影响学生上课情况，确定要删除吗？', {icon: 3, title:'提示'}, function(index){
          if(id != null) {
            //初始化课程分页信息
            that.$post(
              that.urls.deleteCurriculum, {
                "id": id
              }
            )
            .then(function(res) {
              let msg = "";
              if(res.success) {
                msg = '删除课程成功！';
                //重新渲染数据
                that.searchTodo();
              } else {
                msg = '删除课程失败！';
              }
              layer.msg(msg, {
                time: 3000, //3s后自动关闭
              });
            })
          }
        });
      }
		},
		//下载资源
		downloadResources: function(filePath) {
      if (filePath == null || filePath == "") {
        layer.msg("暂无资料", {
          time: 3000, //3s后自动关闭
        });
        return;
      }
      window.location.href = this.urls.download + "?path=" + filePath;
		},
    //资料打包下载
    downloadPack: function (urls) {
      if (urls == null || urls == "") {
        layer.msg("暂无资料", {
          time: 3000, //3s后自动关闭
        });
        return;
      }
      window.location.href = this.urls.downloadPack + "?paths=" + urls;
    },
	}
}
